import {Form,Modal} from 'antd'

import {useEffect} from 'react'
import CamundaAPI from "@/api/CamundaApi.js";

const useCompleteTask = (props) =>{

    const taskId = props.taskId;

    const [form] = Form.useForm();

    const completeTask = () => {
        const params = form.getFieldsValue();
        params.processVar = JSON.parse(params.processVar)
        CamundaAPI.completeTask(params).then(r => {
            if(r.code == '0'){
                Modal.success({
                    title:"Task Be Completed Successful",
                    centered: true,
                    okText: "确认",
                    width:700,
                    onOk() {
                      // 弹出登录弹框
                    },
                  });
            }
            
        })
    }
    useEffect(() => {
   
        form.setFieldsValue({
            taskId,
          processVar: "{\n" + '"name":"zhangsan",\n' + '"age":"5"\n' + "}",
        });
      }, []);


    return {
        form,
        taskId,
        completeTask
    }
}

export default useCompleteTask;